<template slot-scope="scope">
  <div class="main-content">
    <div style="height: 100px; padding-top: 30px;background-color: rgb(238, 238, 238)">
      <div style="width: 68%;display: flex;margin-left: auto;margin-right: 260px;">
        <div style="flex: 2;color: #6a6aa8; font-size: 30px; font-weight: bold;">管 理 员 公 告 栏</div>
        <div style="flex: 8;">
          <button style=" margin-right: -700px;width: 80px; height: 40px; border-radius: 10px; font-weight: bold; border-color: aquamarine;font-size: 18px;" @click="addnotice">新增公告</button>
        </div>
      </div>
    </div>

    <div style="display: flex;">
      <div class="left"></div>
      <div style="width: 68%; height: 100vh; background-color: #e1dfdf; border-radius: 10px;">
        <div style="margin: 30px 0;" v-for="item in typeData">
          <div style="display: flex;">
            <div style="margin-left: 10px; font-size: 16px; width: 100px;">{{ item.noticename }}</div>
            <div style="margin-left: 10px; font-size: 16px;">{{ item.notice }}</div>
            <div style="margin-left: auto;margin-right: 20px; font-size: 16px;">{{ item.time }}</div>
          </div>
        </div>
      </div>
      <div class="right"></div>
    </div>

    <!--新增公告模块-->
    <div >
      <el-dialog title="公告信息" :visible.sync="dialogFormVisible" >
        <el-form :model="form" style="text-align: center;">
          <el-form-item label="公告标题" :label-width="formLabelWidth">
            <el-input v-model="form.noticename" autocomplete="off" style="width: 80%;"></el-input>
          </el-form-item>
          <el-form-item label="公告内容" :label-width="formLabelWidth">
            <el-input type="textarea" v-model="form.notice" autocomplete="off" style="width: 80%;"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" >
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitnotice">确 定</el-button>
        </div>
      </el-dialog>
    </div>

  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  data() {
    return {
      typeData: [],
      dialogFormVisible: false,
      formLabelWidth: 100,
      form: {
        noticename: '',
        notice: '',
      },
    }
  },
  created() {
    this.findByNotice();

  },
  methods:{
    findByNotice() {
      request.post("/notice/findByNotice").then(res => {
        if (res.code === '0'){
          this.typeData = res.data;
        } else {
          this.$message.error(res.msg);
        }
      })
      this.dialogFormVisible = false;
    },
    addnotice(){
      this.dialogFormVisible = true;
    },
    submitnotice(){
      if (this.form.noticename === null) {
        this.$message.warning("公告标题未填写")
      } else if (this.form.notice === null) {
        this.$message.warning("公告内容未填写")
      } else {
        request.post("notice/addnotice",this.form).then(res => {
          if (res.code === '0') {
            this.$message.success("公告添加成功")
          } else {
            this.$message.error(res.msg)
          }
        })
        this.dialogFormVisible = false;
      }
      this.findByNotice();
    },
  }
}

</script>

<style>

.main-content {
  width: 100%;
  margin: 0 auto;
}

.left {
  width: 16%;
  height: 100vh;
  background-color: rgb(238, 238, 238);
}

.right {
  width: 16%;
  height: 100vh;
  background-color: rgb(238, 238, 238);
}

</style>
